﻿using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Web.UI.HtmlControls;
using System.Web.UI;

using LMD.Lib.DataClass;
using LMD.Constant;
using LMD.Lib.Interface;
using LMD.Lib.Oracle;
using LMD.Lib.Controls;

/// <summary>
/// Summary description for AdminPageManager
/// </summary>
public static class AdminPageManager
{
    public static String BuildEditor_AdminList()
    {
        String sxOutput = String.Empty;
        sxOutput = CustomControls.Create_OTFComboBox(KAdmin.EMPLOYEE_LIST, KLOV.Generic.ICPUSER, String.Empty, String.Empty);
        return sxOutput;
    }

    public static String BuildEditor_FeedSourceList()
    {
        String sxOutput = String.Empty;
        sxOutput += CustomControls.BuildEditor_LabelAndText(KAdmin.FEED_SOURCE_NAME, KControl.INPUT_ID, "Nama Source", String.Empty);
        sxOutput += CustomControls.BuildEditor_LabelAndText(KAdmin.FEED_SOURCE_URL, KControl.INPUT_ID, "URL Aplikasi", String.Empty);
        return sxOutput;
    }

    public static String BuildEditor_FeedGeneratorList()
    {
        String sxOutput = String.Empty;

        String sxLOV = CustomControls.Create_OTFComboBox(KAdmin.FEED_GENERATOR_SOURCE, KLOV.Generic.FEEDSOURCE, String.Empty, String.Empty);

        Dictionary<String, String> dicConString = new Dictionary<String, String>();
        dicConString.Add("ICP", "ICP");
        foreach (ConnectionStringSettings css in ConfigurationManager.ConnectionStrings)
        {
            dicConString.Add(css.Name, css.Name);
        }

        String sxCombo = CustomControls.Create_ComboBox(KAdmin.FEED_GENERATOR_CONN, KControl.DROPDOWN_ID, dicConString, String.Empty);

        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Feed Source", sxLOV);

        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Koneksi", sxCombo);
        sxOutput += CustomControls.BuildEditor_LabelAndText(KAdmin.FEED_GENERATOR_SQL, KControl.INPUT_ID, "SQL", String.Empty, TextboxType.Notes);
        sxOutput += CustomControls.BuildEditor_LabelAndText(KAdmin.FEED_GENERATOR_DESC, KControl.INPUT_ID, "Deskripsi", String.Empty);
        sxOutput += CustomControls.BuildEditor_LabelAndText(KAdmin.FEED_GENERATOR_RECUR, KControl.INPUT_ID, "Interval (menit)", String.Empty, TextboxType.Integer);
        return sxOutput;
    }

    public static String BuildEditor_FeedSubscriptionPanel()
    {
        String sxOutput = String.Empty;

        Cached.ICPUserRoleTable ccRole = new Cached.ICPUserRoleTable();
        DataTable dtUserRole = ccRole.GetUserRoleList();

        String sxCombo = CustomControls.Create_ComboBox(dtUserRole, KAdmin.FEED_SUB_USR_TYPE, KAdmin.FEED_SUB_USR_TYPE,
            String.Empty, "ID", "CODE", "ReloadGrid(this)", true);
        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Role User", sxCombo);
        return sxOutput;
    }

    public static String BuildEditor_FeedGeneratorPopup(int iFeedGeneratorId, 
        String sxQuery, String sxDesc, String sxSourceName, String sxConnection, int iInterval)
    {
        String sxReturn = String.Empty;

        Dictionary<String, String> dicConString = new Dictionary<String, String>();
        dicConString.Add("ICP", "ICP");
        foreach (ConnectionStringSettings css in ConfigurationManager.ConnectionStrings)
        {
            dicConString.Add(css.Name, css.Name);
        }

        String sxCombo = CustomControls.Create_ComboBox(KAdmin.FEED_GENERATOR_CONN + "_" + iFeedGeneratorId.ToString(), 
            KControl.DROPDOWN_ID, dicConString, sxConnection);

        String sxEditor = String.Empty;

        sxEditor += CustomControls.BuildFieldSet_PairedLabel("Koneksi", sxCombo);
        sxEditor += CustomControls.BuildEditor_LabelAndText(KAdmin.FEED_GENERATOR_SQL + "_" + iFeedGeneratorId.ToString(),
            KControl.INPUT_ID, "SQL", sxQuery, TextboxType.Notes);
        sxEditor += CustomControls.BuildEditor_LabelAndText(KAdmin.FEED_GENERATOR_DESC + "_" + iFeedGeneratorId.ToString(), 
            KControl.INPUT_ID, "Deskripsi", sxDesc);
        sxEditor += CustomControls.BuildEditor_LabelAndText(KAdmin.FEED_GENERATOR_RECUR + "_" + iFeedGeneratorId.ToString(), 
            KControl.INPUT_ID, "Interval (menit)", iInterval.ToString(), TextboxType.Integer);
        
        sxReturn = String.Format(
            "<div id=\"{1}_{0}\" class=\"popLOV\">" +
                "<fieldset class=\"m_fs_border\" id=\fs_lov_{0}\">" +
                    "<legend>" +
                        "<a class=\"lnk\" href=\"javascript:toggle('{0}');\">Edit SQL for {3}</a>" +
                    "</legend>" +
                    "<dl class=\"m_fs\"><div id=\"div_{0}\">{2}</div></dl>" +
                    "<div id=\"load_{0}\" style=\"float: right; padding-right: 10px;\"></div>" +
                    "<input type=\"button\" id=\"lnkdscd_{0}\" class=\"btn\" style=\"float: right; margin-left: 5px; margin-right: 15px;\"" +
                        " onclick=\"closeEditor();\" value=\"cancel\" />" +
                    "<input type=\"button\" id=\"lnk_{0}\" class=\"btn\" style=\"float: right; margin-left: 5px; margin-right: 5px;\"" +
                        " onclick=\"saveEditor('{0}');\" value=\"save\" />" +
                "</fieldset>" +
            "</div>",
            iFeedGeneratorId.ToString(),
            KControl.GENERICPOPFORM_ID,
            sxEditor,
            sxSourceName
            );
        return sxReturn;
    }

    public static String BuildEditor_FeedSourcePopup(int iFeedSourceId, String sxName, String sxURL)
    {
        String sxReturn = String.Empty;

        String sxEditor = CustomControls.BuildEditor_LabelAndText(KAdmin.FEED_SOURCE_NAME + "_" + iFeedSourceId.ToString(),
            KControl.INPUT_ID, "Nama Source", sxName);
        sxEditor += CustomControls.BuildEditor_LabelAndText(KAdmin.FEED_SOURCE_URL + "_" + iFeedSourceId.ToString(),
            KControl.INPUT_ID, "URL Aplikasi", sxURL);

        sxReturn = String.Format(
            "<div id=\"{1}_{0}\" class=\"popLOV\">" +
                "<fieldset class=\"m_fs_border\" id=\fs_lov_{0}\">" +
                    "<legend>" +
                        "<a class=\"lnk\" href=\"javascript:toggle('{0}');\">Edit Feed Source</a>" +
                    "</legend>" +
                    "<dl class=\"m_fs\"><div id=\"div_{0}\">{2}</div></dl>" +
                    "<div id=\"load_{0}\" style=\"float: right; padding-right: 10px;\"></div>" +
                    "<input type=\"button\" id=\"lnkdscd_{0}\" class=\"btn\" style=\"float: right; margin-left: 5px; margin-right: 15px;\"" +
                        " onclick=\"closeEditor();\" value=\"cancel\" />" +
                    "<input type=\"button\" id=\"lnk_{0}\" class=\"btn\" style=\"float: right; margin-left: 5px; margin-right: 5px;\"" +
                        " onclick=\"saveEditor('{0}');\" value=\"save\" />" +
                "</fieldset>" +
            "</div>",
            iFeedSourceId.ToString(),
            KControl.GENERICPOPFORM_ID,
            sxEditor
            );
        return sxReturn;
    }

    public static String BuildEditor_ProfileSummaryList()
    {
        String sxOutput = String.Empty;

        String sxLOV = CustomControls.Create_OTFComboBox(KAdmin.PROFILE_SUMMARY_INFO_TYPE, KLOV.CompanyProfile.BASICINFOTYPE, String.Empty, String.Empty, TextboxType.Empty);

        sxOutput += CustomControls.BuildFieldSet_PairedLabel("Info Type", sxLOV);

        sxOutput += CustomControls.BuildEditor_LabelAndText(KAdmin.PROFILE_SUMMARY_TEXT, KControl.INPUT_ID, "Text", String.Empty, TextboxType.Notes);
        return sxOutput;
    }

    public static String BuildEditor_ProfileSummaryPopup(int iCustomerInfoTypeId, String sxText, String sxInfoType)
    {
        String sxReturn = String.Empty;
        
        String sxEditor = CustomControls.BuildEditor_LabelAndText(KAdmin.PROFILE_SUMMARY_TEXT + "_" + iCustomerInfoTypeId.ToString(),
            KControl.INPUT_ID, "Text", sxText, TextboxType.Notes);
        
        sxReturn = String.Format(
            "<div id=\"{1}_{0}\" class=\"popLOV\">" +
                "<fieldset class=\"m_fs_border\" id=\fs_lov_{0}\">" +
                    "<legend>" +
                        "<a class=\"lnk\" href=\"javascript:toggle('{0}');\">Edit Text for {3}</a>" +
                    "</legend>" +
                    "<dl class=\"m_fs\"><div id=\"div_{0}\">{2}</div></dl>" +
                    "<div id=\"load_{0}\" style=\"float: right; padding-right: 10px;\"></div>" +
                    "<input type=\"button\" id=\"lnkdscd_{0}\" class=\"btn\" style=\"float: right; margin-left: 5px; margin-right: 15px;\"" +
                        " onclick=\"closeEditor();\" value=\"cancel\" />" +
                    "<input type=\"button\" id=\"lnk_{0}\" class=\"btn\" style=\"float: right; margin-left: 5px; margin-right: 5px;\"" +
                        " onclick=\"saveEditor('{0}');\" value=\"save\" />" +
                "</fieldset>" +
            "</div>",
            iCustomerInfoTypeId.ToString(),
            KControl.GENERICPOPFORM_ID,
            sxEditor,
            sxInfoType
            );
        return sxReturn;
    }
}
